package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueWorkSummaryDao;
import com.prs.crm.domain.doc.IssueWorkSummary;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.WorkSummary;
import com.prs.crm.service.doc.IssueWorkSummaryService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.WorkSummaryService;

public class IssueWorkSummaryServiceImpl extends BaseServiceImpl<IssueWorkSummary,IssueWorkSummaryDao> implements IssueWorkSummaryService{
	private WorkSummaryService workSummaryService;
	private PersonService personService;
	
	@Override
	public void submitIssueWorkSummary(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<WorkSummary> workSummarys = this.getWorkSummaryService().getWorkSummaryByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		
		for(Person person : persons) {
			for(WorkSummary workSummary : workSummarys) {
				IssueWorkSummary issue = new IssueWorkSummary();
				issue.setReceivePerson(person);
				issue.setWorkSummary(workSummary);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public void setWorkSummaryService(WorkSummaryService workSummaryService) {
		this.workSummaryService = workSummaryService;
	}

	public WorkSummaryService getWorkSummaryService() {
		return workSummaryService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	@Override
	public Collection<IssueWorkSummary> getValidIssueWorkSummary(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueWorkSummary(person);
	}

}
